package com.woniu.woniuk16.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.woniuk16.dto.MenuDto;
import com.woniu.woniuk16.dto.RuleSelMenusDto;
import com.woniu.woniuk16.entity.WoniuAccount;
import com.woniu.woniuk16.model.Result;
import com.woniu.woniuk16.param.ChangeRuleParam;
import com.woniu.woniuk16.service.WoniuMenusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tiangle
 * @since 2021-12-17
 */
@RestController
@RequestMapping("/woniuMenus")
public class WoniuMenusController {
    @Autowired
    private WoniuMenusService woniuMenusService;
    @GetMapping("/menus/{id}")
    public Result getMenusByUserId(@PathVariable Integer id){
        List<MenuDto> menus = woniuMenusService.getByUserId(id);
        return Result.getInstance(menus);
    }

    @GetMapping("/menByRule/{id}")
    public Result getMenusByRule(@PathVariable Integer id){
        List<MenuDto> menus = woniuMenusService.getMenusByRule(id);
        return Result.getInstance(menus);
    }

    @GetMapping("/ruleSel/{id}")
    public Result ruleSel(@PathVariable Integer id){
                           RuleSelMenusDto ruleMenu = woniuMenusService.getRuleMenu(id);
        return Result.getInstance(ruleMenu);
    }

    @PostMapping("/changeRule")
    public Result changeRule(@RequestBody ChangeRuleParam changeRuleParam){
        woniuMenusService.changeRule(changeRuleParam);
        return Result.getInstance(null).setMessage("修改成功");
    }
}

